//斗地主
package daily.may0510;

import java.util.ArrayList;
import java.util.Collections;

class Poker {
    //创建牌盒
    private ArrayList<String> pokerBox = new ArrayList<>();
    //创建花色集合
    private ArrayList<String> colors = new ArrayList<>();
    //创建数字集合
    private ArrayList<String> numbers = new ArrayList<>();

    public Poker() {
        addColors();//添加花色
        addNumbers();//添加牌号
        connectPoker();//装牌
        shufflePoker();//洗牌
    }

    //添加花色
    private void addColors() {
        colors.add("♥");//红桃
        colors.add("♠");//黑桃
        colors.add("♣");//梅花
        colors.add("♦");//方块
    }

    //添加牌号
    private void addNumbers() {
        for (int i = 2; i <= 10; i++) {
            numbers.add(String.valueOf(i));//将i转换成字符串
        }
        numbers.add("J");
        numbers.add("Q");
        numbers.add("K");
        numbers.add("A");
    }

    //装牌，拼接花色与数字装入，并装大小王
    private void connectPoker() {
        for (String i : colors) {
            for (String j : numbers) {
                pokerBox.add(i + j);
            }
        }
        pokerBox.add("大王");
        pokerBox.add("小王");
    }

    //洗牌，使用Collections工具类的shuffle方法
    private void shufflePoker() {
        Collections.shuffle(pokerBox);
    }

    //发牌
    void handOutPoker(ArrayList<String> collection1, ArrayList<String> collection2,ArrayList<String> collection3,ArrayList<String> bottom) {
        for (int i = 0; i < pokerBox.size(); i++) {
            //前51张是玩家的，留三张底牌
            if (i < 51) {
                if (0 == i % 3){
                    collection1.add(pokerBox.get(i));
                }else if(1 == i % 3){
                    collection2.add(pokerBox.get(i));
                }else{
                    collection3.add(pokerBox.get(i));
                }
            }else{
                bottom.add(pokerBox.get(i));
            }
        }
    }

    //展示玩家摸到的牌
    void showPoker(ArrayList<String> list){
        System.out.println(list);
    }
}

public class ChinesePokerTest {
    public static void main(String[] args) {
        //创建玩家和底牌集合
        ArrayList<String> player1 = new ArrayList<>();
        ArrayList<String> player2 = new ArrayList<>();
        ArrayList<String> player3 = new ArrayList<>();
        ArrayList<String> bottomPoker = new ArrayList<>();
        //创建游戏对象
        Poker pokerGame = new Poker();
        pokerGame.handOutPoker(player1,player2,player3,bottomPoker);
        pokerGame.showPoker(player1);
        pokerGame.showPoker(player2);
        pokerGame.showPoker(player3);
        pokerGame.showPoker(bottomPoker);
    }
}
